﻿using System.Text;

namespace Freedom.WinCommon.Collections
{
    /// <summary>
    /// LoadingStateBuilder
    /// </summary>
    public class LoadingStateBuilder
    {
        private readonly StringBuilder _builder = new StringBuilder();

        /// <summary>
        /// Appends the state.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="name">The name.</param>
        public void AppendState(ILoadableObject collection, string name)
        {
            var count = collection.LoadedItemsCount;
            if (count.HasValue)
                _builder.AppendFormat("{0} - {1} ", name, count.Value);
        }
        /// <summary>
        /// Appends the state.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="name">The name.</param>
        public void AppendState(int? count, string name)
        {
            if (count.HasValue)
                _builder.AppendFormat("{0} - {1} ", name, count.Value);
        }
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return _builder.ToString();
        }

    }
}